import { Navigate } from "react-router-dom"
import Login from "../pages/login/Login"
import Admin from "../pages/admin/Admin"
import Home from "../pages/admin/components/Home"
import User from "../pages/admin/components/User"
import Role from "../pages/admin/components/Role"
import Category from "../pages/admin/components/mail/Category"
import Product from "../pages/admin/components/mail/Product"
import Bar from "../pages/admin/components/charts/Bar"
import Line from "../pages/admin/components/charts/Line"
import Pie from "../pages/admin/components/charts/Pie"
import Not from "../components/Not"
import store from "@/store"
// import { lazy } from "react"
// const Login = lazy(() => import("../pages/login/Login"))
// const Admin = lazy(() => import("../pages/admin/Admin"))
// const Home = lazy(() => import("../pages/admin/components/Home"))
// const User = lazy(() => import("../pages/admin/components/User"))
// const Role = lazy(() => import("../pages/admin/components/Role"))
// const Category = lazy(() =>import("../pages/admin/components/mail/Category"))
// const Product = lazy(() => import("../pages/admin/components/mail/Product"))
// const Bar = lazy(() => import("../pages/admin/components/charts/Bar"))
// const Line = lazy(() => import("../pages/admin/components/charts/Line"))
// const Pie = lazy(() => import("../pages/admin/components/charts/Pie"))

const routers = [
  {
    path: "/login",
    element: <Login />,
  },
  {
    path: "/admin",
    element: <Admin />,
    children: [
      {
        path: "",
        element: <Navigate to="home" />,
      },
      {
        path: "home",
        label: "首页",
        icon: "shouye",
        element: <Home />,
      },
      {
        path: "mail",
        label: "商品",
        icon: "gongzuotai",
        children: [
          {
            path: "category",
            label: "品类管理",
            icon: "liebiao",
            element: <Category />,
          },
          {
            path: "product",
            element: <Product />,
            label: "商品管理",
            icon: "weixiu",
          },
        ],
      },
      {
        path: "user",
        label: "用户管理",
        icon: "person",
        element: <User />,
      },
      {
        path: "role",
        label: "角色管理",
        icon: "dunpai",
        element: <Role />,
      },
      {
        path: "charts",
        label: "图形图表",
        icon: "shujutubiao",
        children: [
          {
            path: "bar",
            label: "柱形图",
            icon: "tubiao-zhuzhuangtu",
            element: <Bar />,
          },
          {
            path: "line",
            label: "折线图",
            icon: "tubiao-zhexiantu",
            element: <Line />,
          },
          {
            path: "pie",
            label: "饼图",
            icon: "tubiao-bingtu",
            element: <Pie />,
          },
        ],
      },
    ],
  },
  {
    path: "/",
    element: (
      <Navigate
        exact
        from="/"
        to={store.getState().user.isLogin ? "/admin" : "/login"}
      />
    ),
  },
  {
    path: "/*",
    element: <Not />,
  },
]

export default routers
